home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu619.dms / pu619.adf / Utilities / TASKE.LHA / Source / cxhand.c next >
C/C++ Source or Header  |  1993-08-26  |  4KB  |  162 lines

  1. /*
  2.  * Copyright (c) 1993 Michael D. Bayne.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that
  6.  * the following conditions are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
  9.  *    following disclaimer.
  10.  *
  11.  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
  12.  *    following disclaimer in the documentation and/or other materials provided with the distribution.
  13.  *
  14.  * 3. All advertising materials mentioning features or use of this software must display the following
  15.  *    acknowledgement:
  16.  *
  17.  *       This product includes software developed by Michael D. Bayne.
  18.  *
  19.  * 4. My name may not be used to endorse or promote products derived from this software without specific prior
  20.  *    written permission.
  21.  *
  22.  * THIS SOFTWARE IS PROVIDED BY MICHAEL D. BAYNE ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
  23.  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24.  * IN NO EVENT SHALL MICHAEL D. BAYNE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  27.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  */
  30.  
  31. #include <exec/types.h>
  32. #include <libraries/commodities.h>
  33. #include <devices/inputevent.h>
  34.  
  35. #include <intuition/intuition.h>
  36. #include <intuition/intuitionbase.h>
  37.  
  38. #include <clib/exec_protos.h>
  39. #include <clib/intuition_protos.h>
  40. #include <clib/gadtools_protos.h>
  41. #include <clib/utility_protos.h>
  42. #include <clib/commodities_protos.h>
  43. #include <clib/alib_protos.h>
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "TaskE_rev.h"
  48. #include "defs.h"
  49.  
  50. #define KILLKEY "ctrl alt k"
  51.  
  52.     struct    MsgPort *tPort;
  53.     CxObj    *tBroker, *killKey;
  54. extern    ULONG    killMode;
  55. extern    struct    IntuitionBase *IBase;
  56.     struct    NewBroker ntBroker = {
  57.         NB_VERSION,
  58.         "Task Exchange", VERS,
  59.         "Task manipulation software",
  60.         0, 0, 0, 0, 0
  61.     };
  62.     
  63. ULONG handleCxMess( void )
  64. {
  65.     struct Window *deadWnd;
  66.     struct Screen *deadScr;
  67.     ULONG msgid, msgtype, lock;
  68.     CxMsg *msg;
  69.  
  70.     while( msg = ( CxMsg * )GetMsg( tPort )) {
  71.         msgid = CxMsgID( msg );
  72.         msgtype = CxMsgType( msg );
  73.         ReplyMsg(( struct Message * )msg );
  74.  
  75.         switch( msgtype ) {
  76.         case CXM_IEVENT:
  77.             switch( msgid ) {
  78.             case EVT_CX_KILL:
  79.                 switch( killMode ) {
  80.                 case WINDOW:
  81.                     lock = LockIBase( 0 );
  82.                     if( IBase->FirstScreen->FirstWindow ) for( deadWnd = IBase->FirstScreen->FirstWindow;
  83.                         !(( deadWnd->Flags )&( WFLG_WINDOWACTIVE )); deadWnd = deadWnd->NextWindow );
  84.                     UnlockIBase( lock );
  85.                     if( deadWnd ) CloseWindow( deadWnd );
  86.                     deadWnd = 0L;
  87.                     killMode = NONE;
  88.                     break;
  89.                 case SCREEN:
  90.                     lock = LockIBase( 0 );
  91.                     deadScr = IBase->FirstScreen;
  92.                     UnlockIBase( lock );
  93.                     for( deadWnd = deadScr->FirstWindow; deadScr->FirstWindow;
  94.                         deadWnd = deadScr->FirstWindow ) {
  95.                         CloseWindow( deadWnd );
  96.                     }
  97.                     deadWnd = 0L;
  98.                     CloseScreen( deadScr );
  99.                     deadScr = 0L;
  100.                     killMode = NONE;
  101.                     break;
  102.                 }
  103.                 break;
  104.             }
  105.             break;
  106.         case CXM_COMMAND:
  107.             switch( msgid ) {
  108.             case CXCMD_DISABLE:
  109.                 ActivateCxObj( tBroker, 0l );
  110.                 break;
  111.             case CXCMD_ENABLE:
  112.                 ActivateCxObj( tBroker, 1l );
  113.                 break;
  114.             case CXCMD_KILL:
  115.                 return( 0 );
  116.                 break;
  117.             default:
  118.                 break;
  119.             }
  120.         default:
  121.             break;
  122.         }
  123.     }
  124.     return( 1 );
  125. }
  126.  
  127. void ShutdownCX( void )
  128. {
  129.     CxMsg *msg;
  130.  
  131.     if( tPort ) {
  132.         if( tBroker ) DeleteCxObjAll( tBroker );
  133.         tBroker = 0l;
  134.         while( msg = ( CxMsg * )GetMsg( tPort )) ReplyMsg(( struct Message * )msg );
  135.         DeletePort( tPort );
  136.         tPort = 0l;
  137.     }
  138. }
  139.  
  140. ULONG SetupCX( void )
  141. {
  142.     ULONG    cxSigFlag;
  143.  
  144.     if( tPort = CreateMsgPort()) {
  145.         ntBroker.nb_Port = tPort;
  146.         cxSigFlag = 1L << tPort->mp_SigBit;
  147.         if( tBroker = CxBroker( &ntBroker, NULL )) {
  148.             if( killKey = HotKey( KILLKEY, tPort, EVT_CX_KILL )) AttachCxObj( tBroker, killKey );
  149.             if(!( CxObjError( tBroker ))) {
  150.                 ActivateCxObj( tBroker, 1l );
  151.                 return( cxSigFlag );
  152.             } else {
  153.                 DeleteCxObjAll( tBroker );
  154.                 tBroker = 0l;
  155.             }
  156.         }
  157.         DeletePort( tPort );
  158.         tPort = 0l;
  159.     }
  160.     return( 0 );
  161. }
  162.